package soap.latherqq.util;

import java.awt.Font;
import java.awt.Window;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

public class UiUtil {
	// 窗口抖动方法
	private static List<Window> shakeWinList = new ArrayList<Window>();

	public static void shakeWin(final Window win) {
		new Thread(new Runnable() {
			public void run() {
				if (!shakeWinList.contains(win)) {
					shakeWinList.add(win);
					int x = win.getX();
					int y = win.getY();
					for (int i = 0; i < 20; i++) {
						if ((i & 1) == 0) {
							x += 3;
							y += 3;
						} else {
							x -= 3;
							y -= 3;
						}
						win.setLocation(x, y);
						try {
							Thread.sleep(50);
						} catch (InterruptedException e1) {
							e1.printStackTrace();
						}
					}
					shakeWinList.remove(win);
				}
			}
		}).start();
	}

	public static void initGlobalFontSetting(Font fnt) {
		FontUIResource fontRes = new FontUIResource(fnt);
	    for(Enumeration<?> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();){
	        Object key = keys.nextElement();
	        Object value = UIManager.get(key);
	        if(value instanceof FontUIResource)
	            UIManager.put(key, fontRes);
	    }
	}
}